class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        num = len(digits)
        for i in range(num - 1, -1, -1):
            tmp = digits[i] + 1
            if tmp > 9:
                digits[i] = tmp % 10
                if i == 0:
                    return [1] + digits
            else:
                digits[i] = tmp % 10
                break
        return digits

class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        num = len(digits)
        for i in range(num - 1, -1, -1):
            if digits[i] == 9:
                digits[i] = 0     
            else:
                digits[i] += 1
                return digits
        digits.insert(0 ,1)
        return digits
